package com.zf.controller;

import com.zf.entity.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ThreadLocalRandom;

/**
 * Student Controller
 */
@RestController
@RequestMapping("/stu")
public class StudentController {

    @GetMapping("/list")
    public ModelAndView getStuListView() {
        ArrayList<Student> studentList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Student student = new Student();
            int randInt = ThreadLocalRandom.current().nextInt(20);
            student.setUsername(String.format("张三_%d_%d", i, randInt));
            studentList.add(student);
        }
        HashMap<String, Object> data = new HashMap<>();
        data.put("stuList", studentList);
        return new ModelAndView("stu_list", data);
    }
}
